package com.mud.ultimate.dialogs;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.mud.ultimate.GameHandler;
import com.mud.ultimate.GameLauncherActivity;
import com.mud.ultimate.R;
import com.mud.ultimate.tasks.AsyncTaskUploadScore;
import com.mud.ultimate.tasks.AsyncTaskUploadScore.UploadCompleteListener;



public class UploadHighScoreDialog extends Activity implements UploadCompleteListener{

	public static int UPLOAD_SCORE_ERROR=100;
		

	private TextView newHighScoreTV;
	private String name;
	private int score;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.upload_highscore_dialog);
		
		name = getIntent().getExtras().getString(GameHandler.USERNAME_KEY);
		score = getIntent().getExtras().getInt(GameHandler.SCORE_KEY);
		
		newHighScoreTV = (TextView)findViewById(R.id.newHighScoreTV);
		newHighScoreTV.setText(String.valueOf(score));
		
		Button uploadButton = (Button)findViewById(R.id.uploadScoreB);
		uploadButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				AsyncTaskUploadScore task = new AsyncTaskUploadScore(UploadHighScoreDialog.this, UploadHighScoreDialog.this, name, score);
				
				task.execute();
				
				
			}
		});
		
		
		Button skipScoreUploadB = (Button)findViewById(R.id.skipScoreUploadB);
		skipScoreUploadB.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				finish();
				
				
			}
		});
	}

	@Override
	public void onTaskComplete(String aResult) {
		setResult(RESULT_OK);
		finish();
		
	}

	@Override
	public void onError(String aError) {
		setResult(UPLOAD_SCORE_ERROR);
		finish();
		
	}
	

	
	
	
}
